/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-10-17 10:56:19
 * @LastEditTime: 2019-10-17 22:30:10
 * @LastEditors: Please set LastEditors
 */

//连接数据库
const connection = require('./coon');
// 调用方法
connection.connect(() => {
    console.log('数据库连接成功')


})
var express = require('express');
var router = express.Router();

/* GET home page. */
// router.get('/', function(req, res, next) {
//   res.render('index', { title: 'Express' });
// });
//登录接口验证
router.post('/checklogin', function(req, res) {
    // 用户名密码验证
    let { username, password } = req.body.params;
    console.log(username, password)

    var sql = `SELECT * from test where username="${username}"and password="${password}"`
        //查
    connection.query(sql, function(err, result) {
        if (err) {
            console.log('[SELECT ERROR] - ', err.message);
            res.send(err.message)
            return;
        } else {
            res.send(result);
            console.log('--------------------------SELECT----------------------------');
            console.log(result);
            console.log('------------------------------------------------------------\n\n');
        }


    });
})

module.exports = router;